package org.ssq.mybatisPlusMonitor.services.impl;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.ssq.mybatisPlusMonitor.entity.SlowSqlLog;
import org.ssq.mybatisPlusMonitor.mapper.SlowSqlLogMapper;
import org.ssq.mybatisPlusMonitor.services.SlowSqlLogService;

import javax.annotation.Resource;

@Service
public class SlowSqlLogServiceimpl implements SlowSqlLogService {
    @Value("${mybatis-plus.monitor.schema}")
    String schema;
    @Resource
    private SlowSqlLogMapper slowSqlLogMapper;
    @Override
    public void CreateSqlLog(String tableName) {
        int tableExist = slowSqlLogMapper.isTableExist(schema, tableName);
        if (tableExist ==0){
            slowSqlLogMapper.createSqlLog(schema+"."+tableName);
        }
    }
    @Async("taskExecutor")
    @Override
    public void saveSqlLog(SlowSqlLog sqlLog) {
        slowSqlLogMapper.addSqlLog(sqlLog);
    }
}
